package com.kphy.common.utils;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

/**
 * spring工具类
 * 
 * @author kstonely
 * @since 2017-6-26
 */
public class SpringUtil implements ApplicationContextAware {
	
	/**
     * 上下文
     */
    private static ApplicationContext applicationContext;
    
	@Override
	public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
		SpringUtil.applicationContext = applicationContext;
	}
	
	/**
     * 根据Bean ID获取Bean
     * 
     * @param beanId
     * @return
     */
    public static Object getBean(String beanId) {
        return applicationContext.getBean(beanId);
    }
}
